using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace Core
{
    [XmlRoot("helpImage")]
    public class HelpImage : HelpItem, ISavable
    {
        private FileInfo _contentFile = null;

        [XmlIgnore]
        public FileInfo ContentFile
        {
            get { return _contentFile; }
            set { _contentFile = value; }
        }

        private string _name = string.Empty;

        public string name
        {
            get { return _name; }
            set { _name = value; }
        }

        private string _createdDate = string.Empty;

        public string createdDate
        {
            get { return DateTime.Now.ToString(Utils.DEFAULT_DATETIME_FORMAT_STRNG); }
            set { _createdDate = value; }
        }
        private string _changedDate = string.Empty;

        public string changedDate
        {
            get { return DateTime.Now.ToString(Utils.DEFAULT_DATETIME_FORMAT_STRNG); }
            set { _changedDate = value; }
        }
        private string _author = string.Empty;

        public string author
        {
            get { return _author; }
            set { _author = value; }
        }
        private string _version = string.Empty;

        public string version
        {
            get { return _version; }
            set { _version = value; }
        }

        private string _contentFileExtension = string.Empty;

        public string contentFileExtension
        {
            get { return _contentFileExtension; }
            set { _contentFileExtension = value; }
        }

        [XmlIgnore]
        public string ContentFileFullName
        {
            get
            {
                string result = string.Empty;
                if (ContentFile != null)
                {
                    string extension = ContentFile.Extension;
                    result = string.Concat(HCProjectManager.CurrentProject.ContentFolder.FullName, "\\", this.id, extension);
                }
                return result;
            }
        }

        public void SaveToDisk()
        {
            if (HCProjectManager.CurrentProject != null)
            {
                SaveManifestEntry();

                //Save the actual file
                if (ContentFile != null && string.Compare(ContentFile.FullName, ContentFileFullName, true) != 0)
                {
                    if(ContentFile != null && !File.Exists(ContentFileFullName))
                        ContentFile.CopyTo(ContentFileFullName, true);

                    ContentFile = new FileInfo(ContentFileFullName);
                }
            }
        }

        public override void Delete()
        {
            base.Delete();

            //Also has the actual file to delete
            if (File.Exists(ContentFileFullName))
                File.Delete(ContentFileFullName);
        }
    }
}
